﻿namespace Taobao.Tools
{
    using Castle.ActiveRecord;
    using Castle.ActiveRecord.Framework.Config;
    using System;
    using System.Diagnostics;
    using System.Reflection;
    using System.Windows.Forms;
using Taobao.Top.Api.Request;
using Taobao.Top.Api;

    internal static class Program
    {
        [STAThread]
        private static void Main()
        {
            XmlConfigurationSource source = new XmlConfigurationSource("ARconfig.xml");
            ActiveRecordStarter.Initialize(Assembly.Load("Taobao.Model"), source);
            Console.WriteLine("初始化成功");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Test();

            if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
            {
                MessageBox.Show("应用程序已经在运行了");
            }
            else
            {
                Application.Run(new Form1());
            }
        }


        static void Test()
        {
            TopXmlRestClient topClient;
            TradeFullinfoGetRequest req;
            Taobao.Top.Api.Domain.Trade rsp;
            Exception exp;
            topClient = CreateClient();
            req = new TradeFullinfoGetRequest();
            //req.Fields = "num_iid,seller_nick, buyer_nick, title, type, created, sid, tid,  status, payment, discount_fee, adjust_fee, post_fee, total_fee, pay_time, buyer_memo, seller_memo, alipay_no, buyer_message,  iid, num, price, buyer_alipay_no, receiver_name, receiver_state, receiver_city, receiver_district, receiver_address, receiver_zip, receiver_mobile, receiver_phone, buyer_email, shipping_type, trade_memo, is_3D ,orders.title, orders.price,orders.oid, orders.num, orders.iid,  orders.status, orders.tid, orders.total_fee, orders.payment, orders.discount_fee, orders.adjust_fee, orders.timeout_action_time,orders.sku_properties_name, orders.item_meal_name, item_memo ";
            req.Fields = "num_iid,seller_nick, buyer_nick, title, type, created, sid, tid,  status, payment, discount_fee, adjust_fee, post_fee, total_fee, pay_time, buyer_memo, seller_memo, alipay_no, buyer_message,  iid, num, price, buyer_alipay_no, receiver_name, receiver_state, receiver_city, receiver_district, receiver_address, receiver_zip, receiver_mobile, receiver_phone, buyer_email, shipping_type, trade_memo, is_3D ,orders,orders.";//.title, orders.price,orders.oid, orders.num, orders.iid,  orders.status, orders.tid, orders.total_fee, orders.payment, orders.discount_fee, orders.adjust_fee, orders.timeout_action_time,orders.sku_properties_name, orders.item_meal_name, item_memo ";                
            req.Tid = new long?(75283711930303);
            try
            {
                rsp = topClient.TradeFullinfoGet(req);
            }
            catch { }
        }
            
        private static TopXmlRestClient CreateClient()
        {
            return new TopXmlRestClient("http://gw.api.taobao.com/router/rest", "12080893", "9c684c9b2be81c8b723970d52faed823");
        }
 
    }
}

